home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-04
/
dm3_src.zip
/
DMMON.C
< prev
next >
Wrap
Text File
|
1990-04-07
|
8KB
|
245 lines
/* ************************************************************************* */
/* */
/* D O O R W A R E M O N I T O R I / O L I R A R Y */
/* */
/* For Mycrosoft & Turbo C */
/* */
/* ************************************************************************* */
/* ************************************************************************* */
/* PROGRAM HISTORY */
/* ************************************************************************* */
/* 06/20/87 Version 1.00 */
/* 06/14/88 Version 1.10 */
/* Change monitor function to not change directory */
/* Change monitor function to build POINTSx.DOR in local dir */
/* */
/* */
/* */
/* */
/* ************************************************************************* */
#include "dmcfg.h" /* Std. defines & includes */
#include "dmdata.h" /* Std DM storage */
/*
*
* Read the monitor data
*
*/
mon_read(node)
int node; /* Monitor node number */
{
FS rfd;
long cur_time();
char nodestr[3];
long ctm;
int i;
sprintf(nodestr, "%d", node); /* Convert node to string */
strcpy(rfd.name ,"timeoff"); /* Build the filename */
strcat(rfd.name, nodestr);
strcat(rfd.name, ".dor");
i = file_open(&rfd, FREAD, FTEXT, FNOCREATE); /* Open TIMEOFFx.DOR */
if(i == 0)
{
if(fgets(dminbuff, 255, rfd.fd) != 0)
{
mon_signoff = atol(dminbuff);
if(fgets(dminbuff, 255, rfd.fd) != 0)
{
mon_user = atoi(dminbuff);
if(fgets(dminbuff, 255, rfd.fd) != 0)
{
mon_points = atoi(dminbuff);
if(fgets(dminbuff, 255, rfd.fd) != 0)
{
mon_max_play = atoi(dminbuff);
if(fgets(dminbuff, 255, rfd.fd) != 0)
{
mon_nulls = atoi(dminbuff);
if(fgets(dminbuff, 255, rfd.fd) != 0)
{
mon_graphics = atoi(dminbuff);
if(fgets(dminbuff, 255, rfd.fd) != 0)
{
strcpy(mon_dir, dminbuff);
if(fgets(dminbuff, 255, rfd.fd) != 0)
{
strcpy(mon_sound, dminbuff);
}
}
}
}
}
}
}
}
file_close(&rfd);
mon_active = 1; /* Flag as present */
user_start = cur_time(); /* Remeber when we started */
user_signoff = mon_signoff; /* time to signoff at */
if(user_signoff < user_start) /* adjust if wrap around */
user_signoff = user_signoff + DAY_SECONDS;
/* ***************************************************************************
ctm = user_start + ((long)mon_max_play * 60L);
if(ctm < user_signoff)
user_signoff = ctm;
*************************************************************************** */
user_nulls = mon_nulls; /* number of nulls required */
user_graphics = mon_graphics; /* graphics flag */
return(1);
}
else
{
mon_active = 0; /* Flag as not present */
return(0);
}
}
/*
*
* Write the monitor data
*
*/
mon_write(node, points)
int node; /* Monitor node number */
int points;
{
FS wfd;
long cur_time();
long seconds;
char nodestr[3];
int i;
sprintf(nodestr, "%d", node); /* Convert node to string */
if(mon_active) /* If monitor is there... */
{
strcpy(wfd.name ,"points");
strcat(wfd.name, nodestr);
strcat(wfd.name, ".dor");
i = file_open(&wfd, FWRITE, FTEXT, FCREATE); /* Create POINTSx.DOR */
if(i == 0) /* If file created OK... */
{
seconds = cur_time(); /* Time after midnight */
fprintf(wfd.fd, "%lu\n", seconds);
fprintf(wfd.fd, "%u\n", points); /* Score this game */
file_close(&wfd);
}
}
return(0); /* All done */
}
/*
*
* Read in the player name
*
*/
mon_player(name, user)
char *name; /* Place to return name */
int user; /* User number */
{
FS rfd; /* Players file descriptor */
long location; /* File offset */
int i;
if(mon_active) /* If monitor is active... */
{
i = 0;
while((mon_dir[i] != ' ') && /* Build the filename */
(mon_dir[i] != '\0') &&
(mon_dir[i] != 0x09) &&
(mon_dir[i] != 0x0a) &&
(mon_dir[i] != 0x0d))
{
rfd.name[i] = mon_dir[i];
i++;
}
if((i > 0) && (rfd.name[i - 1] != '\\') && (rfd.name[i - 1] != ':'))
{
rfd.name[i] = '\\';
i++;
}
rfd.name[i] = '\0';
strcat(rfd.name, "NAMES.DOR");
i = file_open(&rfd, FREAD, FBINARY, FNOCREATE); /* Open the file */
if(i == 0) /* If open is OK */
{
location = (long)(user - 1) * 64L; /* Record location */
if(fseek(rfd.fd, location, 0)) /* If we can't find the spot */
{
file_close(&rfd); /* Close the file */
return(1); /* Exit, can't find name */
}
if(fread(dminbuff, 1, 64, rfd.fd) != 64)
{
file_close(&rfd); /* Close the file */
return(1); /* Exit, can't find name */
}
for(i = 0 ; i < 31 ; i++)
name[i] = dminbuff[i];
name[i] = '\0';
file_close(&rfd); /* Close the file */
return(0); /* Return all OK */
}
else
return(1); /* Exit, can't find name */
}
else
return(2); /* Flag as inactive */
}
/*
*
* Return to the monitor
*
*/
mon_exit(node)
int node;
{
FS wfd;
int i;
char fname[80];
char nname[8];
if(mon_active) /* If it is there... */
{
strcpy(fname, "MONITOR1.EXE");
sprintf(nname, "%d", node);
i = spawnl(P_OVERLAY, fname, fname, nname, NULL);
}
return(0); /* back to where we were */
}